/*
 * Copyright 2008-2009 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ssn.common.web;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import ssn.common.view.AjaxFileView;
import ssn.common.view.DownloadView;
import ssn.common.vo.FileVO;

/**  
 * @Class Name : 
 * @Description : 
 * @Modification Information  
 * @
 * @  수정일      수정자              수정내용
 * @ ---------   ---------   -------------------------------
 * @ 2013.10.05           최초생성
 * 
 * @since 2013. 09.30
 * @version 1.0
 * @see
 */
@Controller
public class FileDownloadController extends CommonController {

	@RequestMapping("/fileDownload.do")
	public ModelAndView fileDownload(@RequestParam("fileInfo") String fileInfo) throws IOException{
		
		ModelAndView mav = new ModelAndView(new DownloadView());
		
		String savePath = propertiesService.getString("file.real.path");
		
		String saveFile = "";
		String oriFileName = "";
		String fileSize = "";
		if(fileInfo.indexOf("**") > -1){
			String[] temp = fileInfo.split("\\*\\*");
			saveFile = temp[0];
			oriFileName = temp[1];
			fileSize = temp[2];
		}
		
		File file = new File(savePath+saveFile);
		
		mav.addObject("file", file);
		mav.addObject("fileName", oriFileName);
		return mav;
	}
}
